package com.example.demo.service.impl;

import com.example.demo.mapper.UITestCaseSuiteMapper;
import com.example.demo.entity.UITestCaseSuite;
import com.example.demo.entity.request.uiTestCaseSuiteReq.UITestCaseSuiteAddReq;
import com.example.demo.entity.request.uiTestCaseSuiteReq.UITestCaseSuiteEditReq;
import com.example.demo.entity.vo.uiTestCaseSuiteVO.UITestCaseSuiteDetailVO;
import com.example.demo.service.UITestCaseSuiteService;
import com.example.demo.utils.DateToStamp;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UITestCaseSuiteServiceImpl implements UITestCaseSuiteService {
    @Resource
    UITestCaseSuiteMapper uiTestCaseSuiteMapper;


    @Override
    public void add(UITestCaseSuiteAddReq req) {
        UITestCaseSuite uiTestCaseSuite = new UITestCaseSuite();
        BeanUtils.copyProperties(req, uiTestCaseSuite);
        uiTestCaseSuite.setCreateTime(DateToStamp.getTimeStampLong());
        uiTestCaseSuite.setUpdateTime(DateToStamp.getTimeStampLong());
        uiTestCaseSuiteMapper.insert(uiTestCaseSuite);
    }

    @Override
    public void update(UITestCaseSuiteEditReq req) {
        UITestCaseSuite uiTestCaseSuite = new UITestCaseSuite();
        BeanUtils.copyProperties(req, uiTestCaseSuite);
        uiTestCaseSuite.setUpdateTime(DateToStamp.getTimeStampLong());
        uiTestCaseSuiteMapper.updateUITestCaseSuite(uiTestCaseSuite);
    }

    @Override
    public UITestCaseSuiteDetailVO detail(Long id) {
        UITestCaseSuiteDetailVO suiteDetailVO = new UITestCaseSuiteDetailVO();
        UITestCaseSuite uiTestCaseSuite = uiTestCaseSuiteMapper.findById(id);
        BeanUtils.copyProperties(uiTestCaseSuite, suiteDetailVO);
        return suiteDetailVO;
    }

    @Override
    public void delete(Long id) {
        uiTestCaseSuiteMapper.deleteById(id);
    }
}
